package com.neusoft.elmboot.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import com.neusoft.elmboot.po.Business;

@Mapper
public interface BusinessMapper {

	@Select("select * from business where orderTypeId=#{orderTypeId} order by businessId")
	public List<Business> listBusinessByOrderTypeId(Integer orderTypeId);
	
	@Select("select * from business where businessId=#{businessId}")
	public Business getBusinessById(Integer businessId);

	@Insert("INSERT INTO business (businessName, businessAddress, businessExplain, businessImg, orderTypeId, starPrice, deliveryPrice, remarks, userId) " +
			"VALUES (#{businessName}, #{businessAddress}, #{businessExplain}, #{businessImg}, #{orderTypeId}, #{starPrice}, #{deliveryPrice}, #{remarks}, #{userId})")
	@Options(useGeneratedKeys = true, keyProperty = "businessId", keyColumn = "businessId")  // 获取自增的businessId
	int insertBusiness(Business business);

	/**
	 * 根据 userId 查询对应的商家信息
	 * @param userId 用户ID
	 * @return 商家对象
	 */
	@Select("SELECT * FROM business WHERE userId = #{userId}")
	Business findBusinessByUserId(String userId);

}
